#ifndef __INCtimerManagerh
#define __INCtimerManagerh

#include <atomic>
#include <timer.h>
#include <unordered_map>
#include <string>
#include <memory>
#include <objbase.h>

class TimerManager : public objbase
{
public:
    using Callback = Timer::Callback;
    DECLARE_CTOR_DTOR(TimerManager);
    OBJBASE_EXTERN_MEMBER_IMPL();
    STATUS addTimer(const std::string& id, unsigned int intervalSec, Callback callback);
    STATUS removeTimer(const std::string& id);
    STATUS startTimer(const std::string& id);
    STATUS stopTimer(const std::string& id);
    STATUS resetTimer(const std::string& id);
    bool isTimerRunning(const std::string& id);
    bool hasTimer(const std::string& id);

private:
    void startAllTimers();
    void stopAllTimers();
    void clearAllTimers();
    PROCESS_DESC(sysShutdown);

private:
    DISABLE_COPY_CLASS(TimerManager);
    std::unordered_map<std::string, std::unique_ptr<Timer>> m_timers;
    std::mutex m_mutex;
    std::atomic<bool> stoped;
};


#endif
